/**
 * 反转一个单链表
 * 输入: 1->2->3->4->5->NULL
 * 输出: 5->4->3->2->1->NULL  
 */

var reverseList = function(head) {
  let [prev,curr] = [null,head]
  while(curr){
    let tmp = curr.next
    curr.next = prev
    prev = curr 
    curr = tmp
  }
};

/**
 * 两两交换链表的节点
 */

 var swapPairs = (head)=>{
  if (head === null|| head.next === null) {
    return head;
  }
   let newHead = head.next
   head.next = swapPairs(head.next)
   newHead.next = head
   return newHead
 }

 /**
  * 判断链表是否存在环形链表
  */
 //快慢指针
 const hasCycle = (head)=>{
   if(!head||!head.next)return false
   let slow = head
   let fast = head.next
   while(slow !==fast){
    if (!fast || !fast.next) {
      return false;
    }
    slow = slow.next;
    fast = fast.next.next;
   }
   return true
 }
 
 //fun2
 const hasCycle2 = (head)=>{
   while(head){
     if(head.val === 'jsliang'){
       return true
     }else{
       head.val ='jsliang'
     }
     head = head.next
   }
   return false
 }
